/*
 * @Date: 2021-08-26 10:08:11
 * @Author: Acckno1
 * @LastEditTime: 2021-09-07 20:34:42
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}


const int MAX_N = 40010;
const int MAX_M = 110;

struct Students {
    int id;
    int gE, gI, gF;
    int choices[6];
    bool operator< (const Students& b) const {
        if (gF != b.gF) return gF > b.gF;
        else return gE > b.gE;
    }
    bool operator== (const Students& b) const {
        return gF == b.gF && gE == b.gE;
    }
}stu[MAX_N];

bool cmp(Students& a, Students& b) {
    return a.id < b.id;
}

int quota[MAX_M];
inline void solution() {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < m; i++) {
        scanf("%d", &quota[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &stu[i].gE, &stu[i].gI);
        for (int j = 0; j < k; j++) {
            scanf("%d", &stu[i].choices[j]);
        }
        stu[i].gF = stu[i].gE + stu[i].gI;
        stu[i].id = i;
    }

    sort(stu, stu + n);
    vector<vector<Students>>sch(m);

    //学生按排名与志愿进行选学校
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
            int schId = stu[i].choices[j];
            int last = sch[schId].size() - 1;
            //如果学校招生未满 或 学校招的最后一名同学与当前同学排名相同
            if (quota[schId] > sch[schId].size()
                || sch[schId][last] == stu[i]) {
                sch[schId].push_back(stu[i]);
                break;
            }
        }
    }

    for (int i = 0; i < m; i++) {
        auto& item = sch[i];
        //按学生id字母序输出
        sort(item.begin(), item.end(), cmp);
        for (int j = 0; j < item.size(); j++) {
            if (j) printf(" ");
            printf("%d", item[j].id);
        }
        printf("\n");
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}